package com.haierp.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.haierp.mapper.PackageTypeMapper;
import com.haierp.model.PackageType;
import com.haierp.service.IPackageTypeService;

@Service
public class PackageTypeServiceImpl extends SuperServiceImpl<PackageTypeMapper, PackageType>  implements IPackageTypeService {

	@Autowired
	private PackageTypeMapper packageTypeMapper;

	@Override
	public PackageType findPackageType(Long id) {
		return packageTypeMapper.selectById(id);
	}

	@Override
	public void deletePackageType(Long id) {
		packageTypeMapper.deleteById(id);
	}

	@Override
	public void addPackageType(PackageType packageType) {
		packageTypeMapper.insert(packageType);
	}

	@Override
	public void updatePackageType(PackageType packageType) {
		packageTypeMapper.updateSelectiveById(packageType);
	}

	@Override
	public List<PackageType> queryPackageTypeList() {
		return packageTypeMapper.selectList(null);
	}

	@Override
	public void addPackageTypes(List<PackageType> packageTypes) {
		// 获取新的packageType ，数据库最大值加1
		Integer packageType = getMaxTypeValue();
		packageTypes.forEach(pt->pt.setPackageType(packageType));
		packageTypeMapper.insertBatch(packageTypes);
	}

	@Override
	public Integer getMaxTypeValue() {
		Integer packageType = packageTypeMapper.getMaxTypeValue();
		if(packageType!=null){
			packageType++;
		}else{
			packageType = 1;
		}
		return packageType;
	}

	
	

	
}
